<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<?php
/**
 * Created by PhpStorm.
 * User: dapeng
 * Date: 2018/9/27
 * Time: 上午10:46
 */

//$user = $_GET['user'];//GET会把信息显示在地址栏
//$pass = $_GET['pass'];

$user = $_POST['user'];//POST可以隐藏,安全一些
$pass = $_POST['pass'];


//已经完成了连接数据库
$pdo = new PDO("mysql:dbname=test0926;host=127.0.0.1","root","");
//    echo "连接成功";//没有错误,代表成功
//连接后马上改变编码
$pdo->exec("SET NAMES 'utf8';");
$sql = "INSERT INTO tb_user(NAME,pass) VALUES('{$user}','{$pass}');";

//查到pdo对象结果集
$res = $pdo->exec($sql);
if($res > 0){
    echo "添加成功{$res}条数据";
}else{
    echo "添加失败";
    var_dump($pdo->errorInfo());
}

